//
//  MainViewController.m
//  UI06_UIControl_UISegmentedControl_UISlider_UIImageView
//
//  Created by Scott on 15/4/23.
//  Copyright (c) 2015年 www.lanou3g.com 蓝欧3G. All rights reserved.
//

#import "MainViewController.h"

@interface MainViewController ()

@property (nonatomic, retain) UILabel *label1;

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    
#pragma mark - 知识点1 UIControl 的作用
    /**
     * @brief 讲解
     *
     * UIControl 是所有控制控件(UIButton, UISlider, UISegmentedcontrol)的基类.
     *
     * 核心功能: 通过addTarget:action:forControlEvents:方法添加事件
                通过removeTarget:action:forControlEvents: 移除事件
     
     *
     */
    
#pragma mark - 知识点2 UISegmentedControl使用
/**
 * @brief 讲解
 *
 * UISegmentedControl 是iOS中的分段控件
 * 每个segment都能被点击, 相当于集成了若干个button
 * 通常我们点击不同的segment来切换不同的view
 */
    /* 创建UISegmentedControl 对象 
     * initWithItems: 参数是数组
     */
    
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"黄色", @"蓝色", @"红色"]]; /* 数组字面量写法 */
    
    segment.frame = CGRectMake(20, 60, self.view.frame.size.width - 60, 40);
    [self.view addSubview:segment];
    [segment release];
    
    /* 常用的API */
    segment.tintColor = [UIColor redColor]; /* 色调颜色 */
    segment.selectedSegmentIndex = 1; /* 默认选中哪个段 */
    [segment setTitle:@"dd" forSegmentAtIndex:0]; /* 为指定的分段设置标题 */
    
    [segment addTarget:self action:@selector(segmentClick:) forControlEvents:UIControlEventValueChanged];
    
    
    
#pragma mark - 知识点3 UISlider 使用
/**
 * @brief 讲解
 *
 * UISlider 是iOS中的滑动控件
 * 通常用于控制视频播放速度, 控制音量等
 * 继承于UIControl. 滑块提供了一系列连续的值, 滑块停在不同的位置, 获取滑块上的值也不同
 */
    
    /* 创建滑动条对象 */
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 120, self.view.frame.size.width - 40, 40)];
    
    [self.view addSubview:slider];
    [slider release];
    
    /* 常用API */
    slider.minimumTrackTintColor = [UIColor redColor]; /* 划过区域的颜色 */
    slider.minimumValueImage = [UIImage imageNamed:@"asmall.png"]; /* 最小值区域的照片 */
    slider.maximumValueImage = [UIImage imageNamed:@"a.png"];
    slider.minimumValue = 17; /* 设置滑块的最小值, 默认为0 */
    slider.maximumValue = 30; /* 设置滑块的最大值, 默认为1 */
    
    [slider addTarget:self action:@selector(slider:) forControlEvents:UIControlEventValueChanged];
    
    [self addLabelView];
    
    
#pragma mark - 知识点4 UIImageView 使用
/**
 * @brief 讲解
 *
 * UIImageViw 相当于一个相框, 专门用作显示图片, 可以存放一个图片或一组图片
 */
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.jpg"]];;
    imageView.frame = CGRectMake(20, 200, self.view.frame.size.width - 40, 250);
    [self.view addSubview:imageView];
    [imageView release];
    
    /* 常用的API (和动画相关) 
     * 详见"控制僵尸行走速度"
     */
    

#pragma mark - 知识点5 已学类的继承关系
/**
 * @brief 将之前学过的类进行一个理顺.
 */
    
}


- (void)slider:(UISlider *)slider
{
    /* 滑动滑块改变view的透明度 */
//    self.view.alpha = 1 - slider.value;
    
    /* 滑动滑块改变lable字体大小 */
    self.label1.font = [UIFont systemFontOfSize:slider.value];


    
    
}

- (void)segmentClick:(UISegmentedControl *)segment
{
    NSLog(@"index: %ld", segment.selectedSegmentIndex);
    
    /* 选中不同的segment更改view 的背景颜色 */
    switch (segment.selectedSegmentIndex) {
        case 0:
            self.view.backgroundColor = [UIColor yellowColor];
            break;
        case 1:
            self.view.backgroundColor = [UIColor blueColor];
            break;
        case 2:
            self.view.backgroundColor = [UIColor redColor];
            break;
        default:
            break;
    }
    
}


- (void)addLabelView
{
    self.label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 450, 300, 100)];
    self.label1.numberOfLines = 0;
    self.label1.text = @"sdfsdfsdfsdfdsfsdfsdfsdfsdfsd";
    self.label1.layer.borderColor = [UIColor grayColor].CGColor;
    self.label1.layer.borderWidth = 0.5;
    self.label1.layer.cornerRadius = 5.f;

    [self.view addSubview:self.label1];
    [_label1 release];
}

- (void)dealloc
{
    [_label1 release];
    [super dealloc];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
